/*
day480 
2020.12.20 
*/
#include<iostream>
#include<vector>
using namespace std;

struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};

class Solution {
public:
    ListNode *detectCycle(ListNode *head) {
        ListNode *fast=head,*slow=head;
        while(fast)
        {
        	for(int i=0;i<2 && fast;++i)
			{
				fast=fast->next;
			} 
			
			slow=slow->next;
			
			if(slow==fast) break;
		}
		
		if(!fast)
		{
			return nullptr;
		}
		
		slow=head;
		while(slow!=fast)
		{
			slow=slow->next;
			fast=fast->next;
		}
		
		return slow;
    }
};


int main()
{
	return 0;
 } 
